package com.itheima.easy.controller;

import com.itheima.easy.base.PageResponse;
import com.itheima.easy.base.AjaxResult;
import com.itheima.easy.dto.NursingLevelDto;
import com.itheima.easy.service.NursingLevelService;
import com.itheima.easy.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级信息")
    public AjaxResult<List<NursingLevelVo>> listAll() {
        List<NursingLevelVo> nursingLevelDtos = nursingLevelService.listAll();
        return AjaxResult.success(nursingLevelDtos);
    }

    @PostMapping("/insertBatch")
    @ApiOperation(value = "批量插入护理等级信息")
    public AjaxResult insertBatch(@RequestBody List<NursingLevelDto> nursingLevelDtos) {
        nursingLevelService.insertBatch(nursingLevelDtos);
        return AjaxResult.success();
    }

    @PostMapping("/insert")
    @ApiOperation(value = "插入护理等级信息")
    public AjaxResult insert(@RequestBody NursingLevelDto nursingLevel) {
        nursingLevelService.insert(nursingLevel);
        return AjaxResult.success();
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新护理等级信息")
    public AjaxResult update(@RequestBody NursingLevelDto nursingLevel) {
        nursingLevelService.update(nursingLevel);
        return AjaxResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级信息")
    public AjaxResult delete(@PathVariable("id") Long id) {
        nursingLevelService.delete(id);
        return AjaxResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询护理等级信息")
    public AjaxResult<NursingLevelVo> findById(@PathVariable("id") Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return AjaxResult.success(nursingLevelVo);
    }

    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询护理等级信息")
    public AjaxResult<PageResponse<NursingLevelVo>> listByPage(@RequestParam("pageNum") Integer pageNum,
                                 @RequestParam("pageSize") Integer pageSize,
                                 @RequestParam(value = "name", required = false) String name,
                                 @RequestParam(value = "status", required = false) Integer status) {
        PageResponse<NursingLevelVo> nursingLevelVoPageResponse = nursingLevelService.listByPage(pageNum, pageSize, name, status);
        return AjaxResult.success(nursingLevelVoPageResponse);
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用")
    public AjaxResult enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        nursingLevelService.enableOrDisable(id, status);
        return AjaxResult.success();
    }
}
